﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using ChinaSoft.DBUtility;//Please add references
namespace ChinaSoft.DAL
{
	/// <summary>
	/// 数据访问类:DAL_T_PET_YEARCHK
	/// </summary>
	public partial class DAL_T_PET_YEARCHK
	{
		public DAL_T_PET_YEARCHK()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string PET_YEARCCK_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_PET_YEARCHK");
			strSql.Append(" where PET_YEARCCK_ID=:PET_YEARCCK_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_YEARCCK_ID", OracleType.NVarChar)			};
			parameters[0].Value = PET_YEARCCK_ID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(ChinaSoft.Model.Model_T_PET_YEARCHK model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_PET_YEARCHK(");
			strSql.Append("PET_YEARCCK_ID,ACCEPT_TYPE,ACCEPT_NO,CHARGE_DATE,CHARGER_ID,NOTE,REG_ORG_ID,TAKE_DATE,TAKER_NAME,CHARGE_STATE,CREATE_TIME,CREATOR_ID,UPDATE_TIME,UPDATOR_ID,CARD_NO,CARD_TYPE,REGISTER_NAME)");
			strSql.Append(" values (");
			strSql.Append(":PET_YEARCCK_ID,:ACCEPT_TYPE,:ACCEPT_NO,:CHARGE_DATE,:CHARGER_ID,:NOTE,:REG_ORG_ID,:TAKE_DATE,:TAKER_NAME,:CHARGE_STATE,:CREATE_TIME,:CREATOR_ID,:UPDATE_TIME,:UPDATOR_ID,:CARD_NO,:CARD_TYPE,:REGISTER_NAME)");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_YEARCCK_ID", OracleType.NVarChar),
					new OracleParameter(":ACCEPT_TYPE", OracleType.Number,10),
					new OracleParameter(":ACCEPT_NO", OracleType.NVarChar),
					new OracleParameter(":CHARGE_DATE", OracleType.DateTime),
					new OracleParameter(":CHARGER_ID", OracleType.NVarChar),
					new OracleParameter(":NOTE", OracleType.NVarChar),
					new OracleParameter(":REG_ORG_ID", OracleType.NVarChar),
					new OracleParameter(":TAKE_DATE", OracleType.DateTime),
					new OracleParameter(":TAKER_NAME", OracleType.NVarChar),
					new OracleParameter(":CHARGE_STATE", OracleType.NVarChar),
					new OracleParameter(":CREATE_TIME", OracleType.DateTime),
					new OracleParameter(":CREATOR_ID", OracleType.NVarChar),
					new OracleParameter(":UPDATE_TIME", OracleType.DateTime),
					new OracleParameter(":UPDATOR_ID", OracleType.NVarChar),
					new OracleParameter(":CARD_NO", OracleType.NVarChar),
					new OracleParameter(":CARD_TYPE", OracleType.Number,10),
					new OracleParameter(":REGISTER_NAME", OracleType.NVarChar)};
			parameters[0].Value = model.PET_YEARCCK_ID;
			parameters[1].Value = model.ACCEPT_TYPE;
			parameters[2].Value = model.ACCEPT_NO;
			parameters[3].Value = model.CHARGE_DATE;
			parameters[4].Value = model.CHARGER_ID;
			parameters[5].Value = model.NOTE;
			parameters[6].Value = model.REG_ORG_ID;
			parameters[7].Value = model.TAKE_DATE;
			parameters[8].Value = model.TAKER_NAME;
			parameters[9].Value = model.CHARGE_STATE;
			parameters[10].Value = model.CREATE_TIME;
			parameters[11].Value = model.CREATOR_ID;
			parameters[12].Value = model.UPDATE_TIME;
			parameters[13].Value = model.UPDATOR_ID;
			parameters[14].Value = model.CARD_NO;
			parameters[15].Value = model.CARD_TYPE;
			parameters[16].Value = model.REGISTER_NAME;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ChinaSoft.Model.Model_T_PET_YEARCHK model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_PET_YEARCHK set ");
			strSql.Append("ACCEPT_TYPE=:ACCEPT_TYPE,");
			strSql.Append("ACCEPT_NO=:ACCEPT_NO,");
			strSql.Append("CHARGE_DATE=:CHARGE_DATE,");
			strSql.Append("CHARGER_ID=:CHARGER_ID,");
			strSql.Append("NOTE=:NOTE,");
			strSql.Append("REG_ORG_ID=:REG_ORG_ID,");
			strSql.Append("TAKE_DATE=:TAKE_DATE,");
			strSql.Append("TAKER_NAME=:TAKER_NAME,");
			strSql.Append("CHARGE_STATE=:CHARGE_STATE,");
			strSql.Append("CREATE_TIME=:CREATE_TIME,");
			strSql.Append("CREATOR_ID=:CREATOR_ID,");
			strSql.Append("UPDATE_TIME=:UPDATE_TIME,");
			strSql.Append("UPDATOR_ID=:UPDATOR_ID,");
			strSql.Append("CARD_NO=:CARD_NO,");
			strSql.Append("CARD_TYPE=:CARD_TYPE,");
			strSql.Append("REGISTER_NAME=:REGISTER_NAME");
			strSql.Append(" where PET_YEARCCK_ID=:PET_YEARCCK_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ACCEPT_TYPE", OracleType.Number,10),
					new OracleParameter(":ACCEPT_NO", OracleType.NVarChar),
					new OracleParameter(":CHARGE_DATE", OracleType.DateTime),
					new OracleParameter(":CHARGER_ID", OracleType.NVarChar),
					new OracleParameter(":NOTE", OracleType.NVarChar),
					new OracleParameter(":REG_ORG_ID", OracleType.NVarChar),
					new OracleParameter(":TAKE_DATE", OracleType.DateTime),
					new OracleParameter(":TAKER_NAME", OracleType.NVarChar),
					new OracleParameter(":CHARGE_STATE", OracleType.NVarChar),
					new OracleParameter(":CREATE_TIME", OracleType.DateTime),
					new OracleParameter(":CREATOR_ID", OracleType.NVarChar),
					new OracleParameter(":UPDATE_TIME", OracleType.DateTime),
					new OracleParameter(":UPDATOR_ID", OracleType.NVarChar),
					new OracleParameter(":CARD_NO", OracleType.NVarChar),
					new OracleParameter(":CARD_TYPE", OracleType.Number,10),
					new OracleParameter(":REGISTER_NAME", OracleType.NVarChar),
					new OracleParameter(":PET_YEARCCK_ID", OracleType.NVarChar)};
			parameters[0].Value = model.ACCEPT_TYPE;
			parameters[1].Value = model.ACCEPT_NO;
			parameters[2].Value = model.CHARGE_DATE;
			parameters[3].Value = model.CHARGER_ID;
			parameters[4].Value = model.NOTE;
			parameters[5].Value = model.REG_ORG_ID;
			parameters[6].Value = model.TAKE_DATE;
			parameters[7].Value = model.TAKER_NAME;
			parameters[8].Value = model.CHARGE_STATE;
			parameters[9].Value = model.CREATE_TIME;
			parameters[10].Value = model.CREATOR_ID;
			parameters[11].Value = model.UPDATE_TIME;
			parameters[12].Value = model.UPDATOR_ID;
			parameters[13].Value = model.CARD_NO;
			parameters[14].Value = model.CARD_TYPE;
			parameters[15].Value = model.REGISTER_NAME;
			parameters[16].Value = model.PET_YEARCCK_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string PET_YEARCCK_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_PET_YEARCHK ");
			strSql.Append(" where PET_YEARCCK_ID=:PET_YEARCCK_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_YEARCCK_ID", OracleType.NVarChar)			};
			parameters[0].Value = PET_YEARCCK_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string PET_YEARCCK_IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_PET_YEARCHK ");
			strSql.Append(" where PET_YEARCCK_ID in ("+PET_YEARCCK_IDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ChinaSoft.Model.Model_T_PET_YEARCHK GetModel(string PET_YEARCCK_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select PET_YEARCCK_ID,ACCEPT_TYPE,ACCEPT_NO,CHARGE_DATE,CHARGER_ID,NOTE,REG_ORG_ID,TAKE_DATE,TAKER_NAME,CHARGE_STATE,CREATE_TIME,CREATOR_ID,UPDATE_TIME,UPDATOR_ID,CARD_NO,CARD_TYPE,REGISTER_NAME from T_PET_YEARCHK ");
			strSql.Append(" where PET_YEARCCK_ID=:PET_YEARCCK_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_YEARCCK_ID", OracleType.NVarChar)			};
			parameters[0].Value = PET_YEARCCK_ID;

			ChinaSoft.Model.Model_T_PET_YEARCHK model=new ChinaSoft.Model.Model_T_PET_YEARCHK();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["PET_YEARCCK_ID"]!=null && ds.Tables[0].Rows[0]["PET_YEARCCK_ID"].ToString()!="")
				{
					model.PET_YEARCCK_ID=ds.Tables[0].Rows[0]["PET_YEARCCK_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ACCEPT_TYPE"]!=null && ds.Tables[0].Rows[0]["ACCEPT_TYPE"].ToString()!="")
				{
					model.ACCEPT_TYPE=decimal.Parse(ds.Tables[0].Rows[0]["ACCEPT_TYPE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ACCEPT_NO"]!=null && ds.Tables[0].Rows[0]["ACCEPT_NO"].ToString()!="")
				{
					model.ACCEPT_NO=ds.Tables[0].Rows[0]["ACCEPT_NO"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CHARGE_DATE"]!=null && ds.Tables[0].Rows[0]["CHARGE_DATE"].ToString()!="")
				{
					model.CHARGE_DATE=DateTime.Parse(ds.Tables[0].Rows[0]["CHARGE_DATE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CHARGER_ID"]!=null && ds.Tables[0].Rows[0]["CHARGER_ID"].ToString()!="")
				{
					model.CHARGER_ID=ds.Tables[0].Rows[0]["CHARGER_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["NOTE"]!=null && ds.Tables[0].Rows[0]["NOTE"].ToString()!="")
				{
					model.NOTE=ds.Tables[0].Rows[0]["NOTE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["REG_ORG_ID"]!=null && ds.Tables[0].Rows[0]["REG_ORG_ID"].ToString()!="")
				{
					model.REG_ORG_ID=ds.Tables[0].Rows[0]["REG_ORG_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["TAKE_DATE"]!=null && ds.Tables[0].Rows[0]["TAKE_DATE"].ToString()!="")
				{
					model.TAKE_DATE=DateTime.Parse(ds.Tables[0].Rows[0]["TAKE_DATE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["TAKER_NAME"]!=null && ds.Tables[0].Rows[0]["TAKER_NAME"].ToString()!="")
				{
					model.TAKER_NAME=ds.Tables[0].Rows[0]["TAKER_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CHARGE_STATE"]!=null && ds.Tables[0].Rows[0]["CHARGE_STATE"].ToString()!="")
				{
					model.CHARGE_STATE=ds.Tables[0].Rows[0]["CHARGE_STATE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CREATE_TIME"]!=null && ds.Tables[0].Rows[0]["CREATE_TIME"].ToString()!="")
				{
					model.CREATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CREATOR_ID"]!=null && ds.Tables[0].Rows[0]["CREATOR_ID"].ToString()!="")
				{
					model.CREATOR_ID=ds.Tables[0].Rows[0]["CREATOR_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UPDATE_TIME"]!=null && ds.Tables[0].Rows[0]["UPDATE_TIME"].ToString()!="")
				{
					model.UPDATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["UPDATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["UPDATOR_ID"]!=null && ds.Tables[0].Rows[0]["UPDATOR_ID"].ToString()!="")
				{
					model.UPDATOR_ID=ds.Tables[0].Rows[0]["UPDATOR_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CARD_NO"]!=null && ds.Tables[0].Rows[0]["CARD_NO"].ToString()!="")
				{
					model.CARD_NO=ds.Tables[0].Rows[0]["CARD_NO"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CARD_TYPE"]!=null && ds.Tables[0].Rows[0]["CARD_TYPE"].ToString()!="")
				{
					model.CARD_TYPE=decimal.Parse(ds.Tables[0].Rows[0]["CARD_TYPE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["REGISTER_NAME"]!=null && ds.Tables[0].Rows[0]["REGISTER_NAME"].ToString()!="")
				{
					model.REGISTER_NAME=ds.Tables[0].Rows[0]["REGISTER_NAME"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select PET_YEARCCK_ID,ACCEPT_TYPE,ACCEPT_NO,CHARGE_DATE,CHARGER_ID,NOTE,REG_ORG_ID,TAKE_DATE,TAKER_NAME,CHARGE_STATE,CREATE_TIME,CREATOR_ID,UPDATE_TIME,UPDATOR_ID,CARD_NO,CARD_TYPE,REGISTER_NAME ");
			strSql.Append(" FROM T_PET_YEARCHK ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_PET_YEARCHK ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.PET_YEARCCK_ID desc");
			}
			strSql.Append(")AS Row, T.*  from T_PET_YEARCHK T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "T_PET_YEARCHK";
			parameters[1].Value = "PET_YEARCCK_ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

